package com.cavy.platform.server.domain.message;

import com.cavy.platform.server.BeansProvider;
import com.cavy.platform.server.domain.AgentOnline;
import com.cavy.platform.server.service.AgentSessionService;
import org.springframework.stereotype.Service;

import javax.websocket.Session;

/**
 * @author 唐旭
 * @Date 2018/7/24
 * 心跳处理
 */
@Service
public class HeartbeatMessageHandler extends AbstractMessageHandlerImpl<HeartbeatMessage> implements MessageHandler {
    @Override
    protected Class<HeartbeatMessage> getTypeClass() {
        return HeartbeatMessage.class;
    }

    @Override
    protected void handler(Session session, HeartbeatMessage message, AgentOnline agent) {
        agent.heartbeat(message);
        AgentSessionService bean = BeansProvider.getBean(AgentSessionService.class);
        assert bean != null;
        bean.addAgent(session, agent.getInfo().getHostname());
    }
}
